﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>参数过滤</h3>
    <b>下接是参数过滤器接口：</b>
    <pre class="brush:csharp;">
        namespace NFinal.Filter
        {
            public interface IParameterFilter
            {
                bool ParameterFilter(NameValueCollection parameters);
            }
        }
    </pre>
    <b>1.实现过滤器接口。</b><br/>
    如果传入参数id小于零，则控制器不会执行，直接返回。<br />
    <pre class="brush:csharp;">
        [AttributeUsage(AttributeTargets.Method)]
        public class LimitNameAttribute : NFinal.Filter.IParameterFilter
        {
            public bool ParameterFilter(NameValueCollection parameters)
            {
                if(parameters["id"]>0)
                {
                    return true;
                }
                return false;
            }
        }
    </pre>
    <b>2.如何使用?</b><br/>
    把该属性放到控制器行为对应的函数上即可。<br />
    <pre class="brush:csharp;">
        using NFinal.Filter;

        public class IndexController : BaseController
        {
            [LimitName]
            public void Index()
            {
                this.Write("Hello World!");
            }
        }
    </pre>
    <p>

    </p>
</body>
</html>